home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / amiga / gui / x / twm93053.lha / twm / list.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-05-29  |  6.9 KB  |  235 lines

  1. /*****************************************************************************/
  2. /**       Copyright 1988 by Evans & Sutherland Computer Corporation,        **/
  3. /**                          Salt Lake City, Utah                           **/
  4. /**  Portions Copyright 1989 by the Massachusetts Institute of Technology   **/
  5. /**                        Cambridge, Massachusetts                         **/
  6. /**                                                                         **/
  7. /**                           All Rights Reserved                           **/
  8. /**                                                                         **/
  9. /**    Permission to use, copy, modify, and distribute this software and    **/
  10. /**    its documentation  for  any  purpose  and  without  fee is hereby    **/
  11. /**    granted, provided that the above copyright notice appear  in  all    **/
  12. /**    copies and that both  that  copyright  notice  and  this  permis-    **/
  13. /**    sion  notice appear in supporting  documentation,  and  that  the    **/
  14. /**    names of Evans & Sutherland and M.I.T. not be used in advertising    **/
  15. /**    in publicity pertaining to distribution of the  software  without    **/
  16. /**    specific, written prior permission.                                  **/
  17. /**                                                                         **/
  18. /**    EVANS & SUTHERLAND AND M.I.T. DISCLAIM ALL WARRANTIES WITH REGARD    **/
  19. /**    TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES  OF  MERCHANT-    **/
  20. /**    ABILITY  AND  FITNESS,  IN  NO  EVENT SHALL EVANS & SUTHERLAND OR    **/
  21. /**    M.I.T. BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL  DAM-    **/
  22. /**    AGES OR  ANY DAMAGES WHATSOEVER  RESULTING FROM LOSS OF USE, DATA    **/
  23. /**    OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER    **/
  24. /**    TORTIOUS ACTION, ARISING OUT OF OR IN  CONNECTION  WITH  THE  USE    **/
  25. /**    OR PERFORMANCE OF THIS SOFTWARE.                                     **/
  26. /*****************************************************************************/
  27.  
  28.  
  29. /**********************************************************************
  30.  *
  31.  * $XConsortium: list.c,v 1.20 91/01/09 17:13:30 rws Exp $
  32.  *
  33.  * TWM code to deal with the name lists for the NoTitle list and
  34.  * the AutoRaise list
  35.  *
  36.  * 11-Apr-88 Tom LaStrange        Initial Version.
  37.  *
  38.  **********************************************************************/
  39.  
  40. #include <stdio.h>
  41. #include "twm.h"
  42. #include "screen.h"
  43. #include "gram.h"
  44.  
  45. struct name_list_struct
  46. {
  47.     name_list *next;        /* pointer to the next name */
  48.     char *name;            /* the name of the window */
  49.     char *ptr;            /* list dependent data */
  50. };
  51.  
  52. /***********************************************************************
  53.  *
  54.  *  Procedure:
  55.  *    AddToList - add a window name to the appropriate list
  56.  *
  57.  *  Inputs:
  58.  *    list    - the address of the pointer to the head of a list
  59.  *    name    - a pointer to the name of the window 
  60.  *    ptr    - pointer to list dependent data
  61.  *
  62.  *  Special Considerations
  63.  *    If the list does not use the ptr value, a non-null value 
  64.  *    should be placed in it.  LookInList returns this ptr value
  65.  *    and procedures calling LookInList will check for a non-null 
  66.  *    return value as an indication of success.
  67.  *
  68.  ***********************************************************************
  69.  */
  70.  
  71. void
  72. AddToList(list_head, name, ptr)
  73. name_list **list_head;
  74. char *name;
  75. char *ptr;
  76. {
  77.     name_list *nptr;
  78.  
  79.     if (!list_head) return;    /* ignore empty inserts */
  80.  
  81.     nptr = (name_list *)malloc(sizeof(name_list));
  82.     if (nptr == NULL)
  83.     {
  84.     twmrc_error_prefix();
  85.     fprintf (stderr, "unable to allocate %d bytes for name_list\n",
  86.          sizeof(name_list));
  87.     Done();
  88.     }
  89.  
  90.     nptr->next = *list_head;
  91.     nptr->name = name;
  92.     nptr->ptr = (ptr == NULL) ? (char *)TRUE : ptr;
  93.     *list_head = nptr;
  94. }    
  95.  
  96. /***********************************************************************
  97.  *
  98.  *  Procedure:
  99.  *    LookInList - look through a list for a window name, or class
  100.  *
  101.  *  Returned Value:
  102.  *    the ptr field of the list structure or NULL if the name 
  103.  *    or class was not found in the list
  104.  *
  105.  *  Inputs:
  106.  *    list    - a pointer to the head of a list
  107.  *    name    - a pointer to the name to look for
  108.  *    class    - a pointer to the class to look for
  109.  *
  110.  ***********************************************************************
  111.  */
  112.  
  113. char *
  114. LookInList(list_head, name, class)
  115. name_list *list_head;
  116. char *name;
  117. XClassHint *class;
  118. {
  119.     name_list *nptr;
  120.  
  121.     /* look for the name first */
  122.     for (nptr = list_head; nptr != NULL; nptr = nptr->next)
  123.     if (strcmp(name, nptr->name) == 0)
  124.         return (nptr->ptr);
  125.  
  126.     if (class)
  127.     {
  128.     /* look for the res_name next */
  129.     for (nptr = list_head; nptr != NULL; nptr = nptr->next)
  130.         if (strcmp(class->res_name, nptr->name) == 0)
  131.         return (nptr->ptr);
  132.  
  133.     /* finally look for the res_class */
  134.     for (nptr = list_head; nptr != NULL; nptr = nptr->next)
  135.         if (strcmp(class->res_class, nptr->name) == 0)
  136.         return (nptr->ptr);
  137.     }
  138.     return (NULL);
  139. }
  140.  
  141. char *
  142. LookInNameList(list_head, name)
  143. name_list *list_head;
  144. char *name;
  145. {
  146.     return (LookInList(list_head, name, NULL));
  147. }
  148.  
  149. /***********************************************************************
  150.  *
  151.  *  Procedure:
  152.  *    GetColorFromList - look through a list for a window name, or class
  153.  *
  154.  *  Returned Value:
  155.  *    TRUE if the name was found
  156.  *    FALSE if the name was not found
  157.  *
  158.  *  Inputs:
  159.  *    list    - a pointer to the head of a list
  160.  *    name    - a pointer to the name to look for
  161.  *    class    - a pointer to the class to look for
  162.  *
  163.  *  Outputs:
  164.  *    ptr    - fill in the list value if the name was found
  165.  *
  166.  ***********************************************************************
  167.  */
  168.  
  169. int GetColorFromList(list_head, name, class, ptr)
  170. name_list *list_head;
  171. char *name;
  172. XClassHint *class;
  173. Pixel *ptr;
  174. {
  175.     int save;
  176.     name_list *nptr;
  177.  
  178.     for (nptr = list_head; nptr != NULL; nptr = nptr->next)
  179.     if (strcmp(name, nptr->name) == 0)
  180.     {
  181.         save = Scr->FirstTime;
  182.         Scr->FirstTime = TRUE;
  183.         GetColor(Scr->Monochrome, ptr, nptr->ptr);
  184.         Scr->FirstTime = save;
  185.         return (TRUE);
  186.     }
  187.  
  188.     if (class)
  189.     {
  190.     for (nptr = list_head; nptr != NULL; nptr = nptr->next)
  191.         if (strcmp(class->res_name, nptr->name) == 0)
  192.         {
  193.         save = Scr->FirstTime;
  194.         Scr->FirstTime = TRUE;
  195.         GetColor(Scr->Monochrome, ptr, nptr->ptr);
  196.         Scr->FirstTime = save;
  197.         return (TRUE);
  198.         }
  199.  
  200.     for (nptr = list_head; nptr != NULL; nptr = nptr->next)
  201.         if (strcmp(class->res_class, nptr->name) == 0)
  202.         {
  203.         save = Scr->FirstTime;
  204.         Scr->FirstTime = TRUE;
  205.         GetColor(Scr->Monochrome, ptr, nptr->ptr);
  206.         Scr->FirstTime = save;
  207.         return (TRUE);
  208.         }
  209.     }
  210.     return (FALSE);
  211. }
  212.  
  213. /***********************************************************************
  214.  *
  215.  *  Procedure:
  216.  *    FreeList - free up a list
  217.  *
  218.  ***********************************************************************
  219.  */
  220.  
  221. void FreeList(list)
  222. name_list **list;
  223. {
  224.     name_list *nptr;
  225.     name_list *tmp;
  226.  
  227.     for (nptr = *list; nptr != NULL; )
  228.     {
  229.     tmp = nptr->next;
  230.     free((char *) nptr);
  231.     nptr = tmp;
  232.     }
  233.     *list = NULL;
  234. }
  235.